package com.awakening.service;

import net.coobird.thumbnailator.Thumbnails;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

/**
 * @Author:AwakeningCode
 * @Date: Created in 12:37 2018\1\23 0023
 */
@Service
public class ThumbnailService {
    public static final int WIDTH = 100;
    public static final int HEIGHT = 100;

    public String thumbnail(CommonsMultipartFile file,String uploadPath,String realUploadPath){

        try {
            String des = realUploadPath + "/thum_" + file.getOriginalFilename();
            Thumbnails.of(file.getInputStream()).size(WIDTH,HEIGHT).toFile(des);
        }catch (Exception e){
            e.printStackTrace();
        }

        return uploadPath + "/thum_" + file.getOriginalFilename();
    }


}
